package lanqiao;

import java.util.*;

public class lq001 {
    private static class Person {
        int price;
        int count;

        public Person() {
        }

        public Person(int price, int count) {
            this.count = count;
            this.price = price;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "price=" + price +
                    ", count=" + count +
                    '}';
        }
    }



    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nAndS = scanner.nextLine().split(" ");
        int numOfPersons = Integer.parseInt(nAndS[0]);
        int priceForGroup = Integer.parseInt(nAndS[1]);

        ArrayList<Person> persons = new ArrayList<>();
        for (int i = 0; i < numOfPersons; i++) {
            String[] priceAndCount = scanner.nextLine().split(" ");
            int price = Integer.parseInt(priceAndCount[0]);
            int count = Integer.parseInt(priceAndCount[1]);
            Person person = new Person(price, count);
            persons.add(person);
        }
        System.out.println("persons = " + persons);

        int result = new lq001().getResult(persons,numOfPersons,priceForGroup);
        System.out.println("result = " + result);
    }

    private int getResult(ArrayList<Person> persons,int numOfPersons,int priceForGroup) {
        System.out.println("priceForGroup = " + priceForGroup);
        persons.sort(Comparator.comparingInt(p -> p.count));
        System.out.println("persons = " + persons);
        int maxConut = persons.get(numOfPersons-1).count;
        System.out.println("maxConut = " + maxConut);
        int minPriceForSingle = persons.stream().min(Comparator.comparingInt(p->p.price)).get().price;
        System.out.println("minPriceForSingle = " + minPriceForSingle);
        int totalPriceForSingle = 0;
        for (int i = 0; i < numOfPersons; i++) {
            totalPriceForSingle+=persons.get(i).price;
        }
        System.out.println("totalPriceForSingle = " + totalPriceForSingle);

        if (minPriceForSingle>=priceForGroup) {
            return maxConut*priceForGroup;
        }

        int index=0;
        int oldIndex=0;
        int totalPrice=0;
        int currentCount=0;
        for (int i = 1; i <= maxConut; i++) {
            System.out.println("-------第" + i+"次循环------");
            System.out.println("totalPriceForSingle = " + totalPriceForSingle);
            System.out.println("index = " + index);
            System.out.println("currentCount = " + currentCount);
            if (priceForGroup<=totalPriceForSingle) {
                totalPrice+=priceForGroup;
                currentCount++;
                oldIndex=index;
                index = this.nextIndex(index,persons,currentCount);
                for (int j = oldIndex; j < index; j++) {
                    totalPriceForSingle-=persons.get(j).price;
                }
            } else {
                for (int j = index; j < numOfPersons; j++) {
                    System.out.println("totalPrice = " + totalPrice);
                    totalPrice+=persons.get(j).price*(persons.get(j).count-currentCount);
                }
                return totalPrice;
            }
            System.out.println("totalPrice = " + totalPrice);
        }
        return totalPrice;
    }

    private int nextIndex(int index, ArrayList<Person> persons, int currentCount) {
        for (int i = index;i< persons.size(); i++) {
            if (persons.get(i).count-currentCount>0) {
                return i;
            }
        }
        return persons.size();
    }
}
